merge<-function(years){
############ Merge Data ##########
# source('clean_merge__all__merge_bac_data.R')
# data<-clean_merge__all__merge_bac_data(data_adm_raw,data_bac_raw)
# data_merged_complete<-data[[1]]
# data_merged_filtered<-data[[2]]
# rm(data)
# gc()
# test_char_clean<-sort(unique(unlist(unique(strsplit(data_merged_complete$unitate_de_invatamant, "")))))
# test_char_clean<-grep(test_char_clean[1], data_bac_raw$unitate_de_invatamant, value=TRUE)
# test_char_clean<-unique(data_merged_complete$unitate_de_invatamant)
# 
# saveRDS(data_merged_complete, file = "data_merged_complete2018")
# saveRDS(data_merged_filtered, file = "data_merged_filtered2018")

############ Merge Data ##########
setwd(wd_code)
source('merge_all_v3.R')
  

for (i in years){
  print(i)
  j<-i-4
  graduation_file_final<-paste("data_bac_raw_gps_",i,sep="")
  admission_file_final<-paste("data_adm_raw_gps_",j,sep="")
  #admission_file_final<-paste("data_adm_hs_ms_siiir_",j,".rds",sep="")
  
  setwd(wd_data_intermediate)
  data_adm_raw<-readRDS(paste(admission_file_final,sep=""))
  data_bac_raw<-readRDS(paste(graduation_file_final,sep=""))
  data<-merge_all(data_adm_raw,data_bac_raw,i)
  
  data_merged_complete<-data[[1]]
  data_merged_filtered<-data[[2]]
  
  saveRDS(data_merged_complete, file = paste("data_merged_complete_",i,sep=""))
  saveRDS(data_merged_filtered, file = paste("data_merged_filtered_",i,sep=""))
  
  rm(data_merged_complete,data_merged_filtered)
  gc()
  print("merge complete")
}
}